<div class="abiturients form">
<fieldset>
 <legend><?php __('<b>Оформление абитуриента</b>');?></legend>
 <table width="100%" cellspacing="2" cellpadding="2">
  <tr>
    <td width="25%" rowspan="5" align="left" valign="top">
    	<table cellspacing="2" cellpadding="2" border=0>
		<tr>
			<td>
				<?php 
				echo $form->create('Abiturient', array('action' => 'prepare'));
				echo $html->image('reload.gif', array('alt' => 'Обновить страницу', 'url' => array('controller' => 'abiturients', 'action' => 'prepare', $this->data['Abiturient']['id'])));
				?>
			</td>
		</tr>
    	<tr>
    	 	<td>
				<?php 
				echo $html->image('print.gif', array('alt' => 'Сформировать заявление', 'url' => array('controller' => 'documents', 'action' => 'anketa', 'abiturient' => $this->data['Abiturient']['id'])));
				?>
			</td>
		</tr>
    	<tr>
    	 	<td>
				<?php 
				echo $html->image('docs.gif', array('alt' => 'Сформировать опись', 'url' => array('controller' => 'documents', 'action' => 'abiturientdocs', 'abiturient' => $this->data['Abiturient']['id'])));
				?>
			</td>
		</tr>		
 		</table>		
	</td>
    <td rowspan="5" align="left" valign="top" width="25%"><?php 
			echo $form->input('id');
			echo $html->image(array('controller'=>'abiturients','action'=>'showimage', $this->data['Abiturient']['id']), array('alt' => 'Фото абитуриента', 'width' => 150, 'height' => 200, 'border' => 1));
			//echo $html->image('enstaine.jpg', array('alt' => 'Фото абитуриента', 'width' => 150, 'height' => 192, 'border' => 1));
		?></td>
    <td>Фамилия</td>
    <td><?php echo $form->input('lastname', array('label' => '', 'size' => 30)); ?></td>
  </tr>
  <tr>
    <td>Имя</td>
    <td><?php echo $form->input('firstname', array('label' => '', 'size' => 30)); ?></td>
  </tr>
  <tr>
    <td width="25%">Отчество</td>
    <td width="50%"><?php echo $form->input('surname', array('label' => '', 'size' => 30)); ?></td>        
  </tr>
   <tr>
    <td width="25%">Пол</td>
    <td width="50%"><?php echo $form->input('gender_id', array('label' => '')); ?></td>
  </tr>
  <tr>
    <td width="25%">Дата рождения</td>
    <td width="50%"><?php echo $form->input('birthdate', array('label' => '', 'minYear' => 1950, 'maxYear' =>2000)); ?></td>
  </tr>
  <tr>
  	<td colspan="4"><hr /></td>
  </tr>
  <tr>
    <td colspan="4"><strong>Паспортные данные</strong></td>
  </tr>
  <tr>
    <td width="25%">серия</td>
    <td width="25%"><?php echo $form->input('passport_ser', array('label' => ''));
 ?></td>
    <td width="25%" align="right">номер</td>
    <td width="50%"><?php echo $form->input('passport_num', array('label' => ''));
 ?></td>
  </tr>
  <tr>
    <td width="25%">Место рождения</td>
    <td><?php echo $form->input('passport_birthplace', array('label' => '', 'size' => 50));
 ?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
   <tr>
     <td>Выдан</td>
     <td colspan="3"><?php echo $form->input('passport_data', array('label' => '', 'size' => 100));
 ?></td>
     </tr>
   <tr>
    <td width="25%">Гражданство</td>
    <td width="25%"><?php echo $form->input('citizenship_id', array('options' => $citizenships, 'empty' => 'Выберите гражданство', 'label' => '', 'id' => 'citizenships'), null); ?></td>
    <td width="25%" align="right">Область</td>
    <td width="50%"><?php echo $form->input('region_id', array('options' => $regions, 'empty' => 'Выберите область', 'label' => '', 'id' => 'regions'), null); ?></td>
  </tr>
  <tr>
  	<td colspan="4"><hr /></td>
  </tr>   
   <tr>
    <td colspan="4"><strong>Документ об образовании</strong></td>
  </tr>
   <tr>
    <td width="25%">тип документа</td>
    <td width="25%"><?php echo $form->input('educationdoctype_id', array('options' => $educationdoctypes, 'empty' => 'Выберите тип документа', 'label' => '', 'id' => 'educationdoctypes'), null); ?></td>
    <td width="25%" align="right">оригинал</td>
    <td width="50%"><?php echo $form->input('originaleducationdoc', array('label' => '')); ?></td>
  </tr>
   <tr>
    <td width="25%">данные</td>
    <td colspan="3"><?php echo $form->input('educationdocdata', array('label' => '', 'size' => 100)); ?></td>
  </tr>
   <tr>
    <td width="25%">Год окончания школы</td>
    <td width="25%"><?php echo $form->input('schoolgraduated', array('label' => '')); ?></td>   
    <td width="25%">Ин. язык в школе</td>
    <td width="50%"><?php echo $form->input('schoolflanguage_id', array('options' => $schoolflanguages, 'empty' => 'Выберите ин. язык', 'label' => '', 'id' => 'schoolflanguages'), null); ?></td>
  </tr>
  <tr>
  	<td colspan="4"><hr /></td>
  </tr>   
  <tr>
    <td colspan="4"><strong>Контактная информация</strong></td>
  </tr>
   <tr>
    <td width="25%">Место жительства</td>
    <td colspan="3"><?php echo $form->input('adress', array('label' => '', 'cols' => 60, 'rows' => 10)); ?> </td>
  </tr>  
   <tr>
    <td width="25%">телефон</td>
    <td width="25%"><?php echo $form->input('phone', array('label' => '')); ?></td>
    <td width="25%" align="right">моб. телефон</td>
    <td width="50%"><?php echo $form->input('mobile', array('label' => '')); ?></td>
  </tr> 
   <tr>
    <td width="25%">Эл. почта (e-mail)</td>
    <td colspan="2"><?php echo $form->input('email', array('label' => '', 'size' => 40)); ?></td>
    <td width="50%">&nbsp;</td>
  </tr>
  <tr>
  	<td colspan="4"><hr /></td>
  </tr> 
   <tr>
    <td colspan="4"><strong>Родственники</strong></td>
  </tr> 
   <tr>
    <td colspan="3">
    	<?php 
    		if ($relativescount) {
    			foreach ($relatives as $relative):
			    		echo $relativestypes[$relative['Relative']['relativestype_id']];
			    		echo ' - '.$relative['Relative']['fio'];
			    		echo ' (';
			    		echo $html->link(__('редактировать', true), array('controller' => 'relatives', 'action' => 'edit', $relative['Relative']['id'], 'abiturient' => $this->data['Abiturient']['id']), array('target' => '_blank'));
			    		echo ' / ';
			    		echo $html->link(__('удалить', true), array('controller' => 'relatives', 'action' => 'delete', $relative['Relative']['id'] ), array('target' => '_blank'));
			    		echo ')';
			    		echo '<br />';
    			endforeach;	
    		}?>
    </td>
    <td><?php  
    	echo $html->link(__('Добавить родственника', true), array('controller' => 'relatives', 'action' => 'add', 'abiturient' => $this->data['Abiturient']['id']), array('target' => '_blank'));?>
    </td>
  </tr>
    <tr>
  	<td colspan="4"><hr /></td>
  </tr>
  <!-- 
 /******************************************************************************************
 * 
 * 				работа с оценками
 * 
 *****************************************************************************************/	  
   -->
     <tr>
    <td colspan="4"><strong>Данные по предметам (оценки)</strong></td>
  </tr> 
   <tr>
    <td colspan="3">
    	<?php 
    		if ($resultscount){
    			// шапка таблицы
    			echo '
					<table width="100%" cellspacing="0" cellpadding="0" class="art-article">
					  <tr>
					  	<th><strong>Тип оценки</strong></th>
					    <th><strong>предмет-баллы</strong></th>
					    <th><strong>действия</strong></th>
					  </tr>' ;
    			// цикл по выводу предметов с оценками
    			foreach ($results as $result):
    			echo '<tr>';
    			echo '<td>';
    			echo $resulttypes[$result['Result']['resulttype_id']];
    			echo '</td>';    			    			
    			echo '<td>';
    			echo $subjects[$result['Result']['subject_id']]; 
    			echo ' - ';
    			echo '<b>'.$result['Result']['score'].'</b>';
    			echo '</td>';    	
    			echo '<td>';
    			echo $html->link(__('Удалить', true), array('controller' => 'results', 'action' => 'delete', 'id' => $result['Result']['id']), array('target' => '_blank'));
    			echo '</td>';				
    			echo '</tr>';
    			endforeach;    			
    			// конец таблицы
    			echo '</table>';
    		}
    		 
    	?>    			
    </td>
    <td>
    	<?php  
    		echo $html->link(__('Добавить результат (оценку) по предмету', true), array('controller' => 'results', 'action' => 'add', 'abiturient' => $this->data['Abiturient']['id']), array('target' => '_blank'));
    	?>
    </td>
  </tr>
  <tr>
  	<td colspan="4"><hr /></td>
  </tr>  
  <!-- 
 /******************************************************************************************
 * 
 * 				работа с выбранными специальностями
 * 
 *****************************************************************************************/	  
   -->  
  <tr>
	<td colspan="4"><strong>Желаемая специальность</strong></td>
  </tr>
  <tr>
  	<td colspan="3">
  		<?php 
  				$addcontractline = false;
				if ($selectedprofessionscount){
					echo '
								<table width="100%" cellspacing="0" cellpadding="0" class="art-article">
								  <tr>
								    <th><strong>Фак-т</strong></th>
								    <th><strong>Спец-сть</strong></th>
								    <th><strong>Форма об.</strong></th>
								    <th><strong>Тип об.</strong></th>
								<!--    <th><strong>Предм. ЕГЕ</strong></th> -->
								    <th><strong>Баллы</strong></th>
								    <th><strong>МИН Баллы</strong></th>
								    <th><strong>Действия</strong></th>
								  </tr>';
					foreach ($selectedprofessions as $selectedprofession):
						echo '<tr>';
						echo '<td align="center">';
						echo $facultets[$selectedprofession['Profession']['facultet_id']];
						echo '</td>';
						echo '<td>';
						echo $selectedprofession['Profession']['name'];
						echo '</td>';
						echo '<td>';
						echo $selectedprofession['Learningform']['name'];
						echo '</td>';
						echo '<td>';
						echo $selectedprofession['Learningtype']['name'];
						echo '</td>';
						echo '<td>';
						$total_score = 0;
							foreach ($subjectsprofessions as $subjectsprofession):
							if ($subjectsprofession['SubjectsProfession']['profession_id'] == $selectedprofession['Profession']['id'])
							{
								echo $subjects[$subjectsprofession['SubjectsProfession']['subject_id']];
							if ($resultscount){
								foreach ($results as $result):
								if ($result['Result']['subject_id'] == $subjectsprofession['SubjectsProfession']['subject_id']){
									echo ' - ';
									echo $result['Result']['score'];
									$total_score += $result['Result']['score'];
								}
								endforeach;
							}	
								echo '<br />';
							}							
							endforeach;
						echo '<font color="green">Всего - '.$total_score.'</font>';	
						echo '</td>';
						/*
						 *  выводим минимальные баллы по предметам по этой специальности
						 */
						echo '<td>';
						foreach ($minimalresults as $minimalresult):
						if ($minimalresult['Minimalresult']['profession_id'] == $selectedprofession['Profession']['id']){
							echo $subjects[$minimalresult['Minimalresult']['subject_id']];
							echo ' - ' ;
							echo $minimalresult['Minimalresult']['score'];
							echo '<br />';
						}
						endforeach;
						echo '</td>' ;
						echo '<td valign="middle">';
						echo $html->link(__('Удалить', true), array('controller' => 'selectedprofessions', 'action' => 'delete', 'id' => $selectedprofession['Selectedprofession']['id']), array('target' => '_blank'));
						echo '</td>';
						echo '</tr>';		
						if ($selectedprofession['Selectedprofession']['learningtype_id'] ==2){
							$addcontractline = true;
						}													
					endforeach;
				echo '</table>' ;		
				}
		?>	  	
  	</td>
  	<td width="50%">
		<?php
			if ($selectedprofessionscount <12){
			 	echo $html->link(__('Добавить специальность' ,true), array('controller' => 'selectedprofessions', 'action' => 'add', 'abiturient' => $this->data['Abiturient']['id']), array('target' => '_blank'));
			}?>
	</td>
  </tr>
  <?php 
  /*
   	if (!$contractscount){
   		if ($addcontractline){
			echo '<tr><td colspan="4"><hr /></td></tr>';
			echo '<tr>
					<td colspan="4"><strong>Договор на вне бюджетное обучение</strong></td>
				</tr>';		
			echo '<tr>';
			echo '<td colspan="3">НЕТ ДОГОВОРА</td>';		
			echo '<td>';
			echo $html->link(__('Добавить договор по внебюджету' ,true), array('controller' => 'contracts', 'action' => 'add', 'abiturient' => $this->data['Abiturient']['id']), array('target' => '_blank'));
			echo '	<td>';
			echo '</tr>';   			
   		}
	}
	else {
			echo '<tr><td colspan="4"><hr /></td></tr>';
			echo '<tr>
					<td colspan="4"><strong>Договор на вне бюджетное обучение</strong></td>
				</tr>';		
			echo '<tr>';			
			echo '<tr>';
			echo '<td colspan="3">';
			echo '
			<table width="100%" cellspacing="0" cellpadding="0" class="art-article">
			  <tr>
			    <th><strong>Контракт</strong></th>
			    <th><strong>Действия</strong></th>
			  </tr>';
			foreach ($contracts as $contract):
			echo '<tr>';
			echo '<td>'.$contract['Contract']['name'].'</td>';
			echo '<td>';
			echo $html->link(__('Удалить', true), array('controller' => 'contracts', 'action' => 'delete', 'id' => $contract['Contract']['id']), array('target' => '_blank'));
			echo '</td>';
			echo '</tr>';
			endforeach;
			echo'</table>';
			echo '</td>';
			echo '	<td>';
			echo $html->link(__('Добавить договор по внебюджету' ,true), array('controller' => 'contracts', 'action' => 'add', 'abiturient' => $this->data['Abiturient']['id']), array('target' => '_blank'));
			echo '	<td>';		
		echo '</tr>';
	} 
	*/
	 ?>
  <tr>
  	<td colspan="4"><hr /></td>
  </tr>
 <tr>
  	<td colspan="4"><strong>Преимущественное право (приоритет)</strong></td>
  </tr>
  <tr>
  	<td colspan="3">
  		<?php 
  			if($prioritetscount) {
  				echo '
  				<table width="100%" cellspacing="0" cellpadding="0" class="art-article">
				  <tr>
				    <th><strong>Преимущество</strong></th>
				    <th><strong>Действия</strong></th>
				  </tr>
  				';
  				foreach ($abiturientsprioritets as $abiturientsprioritet):
  				echo '<tr>';
  				echo '<td>';
  				echo $prioritets[$abiturientsprioritet['AbiturientsPrioritet']['prioritet_id']];
  				echo '</td>';
  				echo '<td>';
				echo $html->link(__('Удалить', true), array('controller' => 'abiturients_prioritets', 'action' => 'delete', 'id' => $abiturientsprioritet['AbiturientsPrioritet']['id']), array('target' => '_blank'));  				
  				echo '</td>';
  				echo '</tr>';
  				endforeach;
  				echo '</table>';
  			} else {
  				echo 'НЕТ ПРЕИМУЩЕСТВ';
  			}
  		?>
  	</td>
  	<td>
  		<?php 
  		echo $html->link(__('Добавить преимущество' ,true), array('controller' => 'abiturients_prioritets', 'action' => 'add', 'abiturient' => $this->data['Abiturient']['id']), array('target' => '_blank'));
  		?>
  	</td>
  </tr>      
  <tr>
  	<td colspan="4"><hr /></td>
  </tr>
 <tr>
  	<td colspan="4"><strong>Льготы</strong></td>
  </tr>      
   <tr>
     <td colspan="3">
   		<?php 
  			if($privilegescount) {
  				echo '
  				<table width="100%" cellspacing="0" cellpadding="0" class="art-article">
				  <tr>
				    <th><strong>ЛЬготы</strong></th>
				    <th><strong>Действия</strong></th>
				  </tr>
  				';
  				foreach ($abiturientsprivileges as $abiturientsprivilege):
  				echo '<tr>';
  				echo '<td>';
  				echo $privileges[$abiturientsprivilege['AbiturientsPrivilege']['privilege_id']];
  				echo '</td>';
  				echo '<td>';
				echo $html->link(__('Удалить', true), array('controller' => 'abiturients_privileges', 'action' => 'delete', 'id' => $abiturientsprivilege['AbiturientsPrivilege']['id']), array('target' => '_blank'));  				
  				echo '</td>';
  				echo '</tr>';
  				endforeach;
  				echo '</table>';
  			}
  			else {
  				echo 'НЕТ ЛЬГОТ';
  			}
  		?>
	</td>
    <td width="25%">
    <?php 
  		echo $html->link(__('Добавить льготу ' ,true), array('controller' => 'abiturients_privileges', 'action' => 'add', 'abiturient' => $this->data['Abiturient']['id']), array('target' => '_blank'));
  		?>
    </td>

  </tr>
  <tr>
  	<td colspan="4"><hr /></td>
  </tr>          
   <tr>
    <td colspan="4"><strong>Целевой набор</strong></td>
  </tr>
  <tr>
  	<td colspan="3">
  		<?php 
			if ($targetingintakescount == 0){
    			echo 'НЕ УЧАСТВУЕТ В ЦЕЛЕВОМ НАБОРЕ';
    		}
    		else {
    			echo '<table cellspacing="0" cellpadding="0" class="art-article">';
    			foreach ($targetingintakes as $intake) {
    				echo '<tr>';
    				echo '<td>'.'<b>Орган власти</b>'.'</td>';
    				echo '<td>'.'<b>Область</b>'.'</td>';
    				echo '<td>'.'<b>факультет</b>'.'</td>';
    				echo '<td>'.'<b>специальность</b>'.'</td>';
    				echo '<td>'.'<b>форма обучения</b>'.'</td>';
    				echo '<td>'.'<b>тип обучения</b>'.'</td>';
    				echo '<td>'.'<b>Действия</b>'.'</td>';
    				echo '</tr>';
    				echo '<tr>';
    				echo '<td>'.$intake['Tgintakeorg']['name'].'</td>';
    				echo '<td>'.$intake['Region']['name'].'</td>';	
    				echo '<td>'.$intake['Facultet']['name'].'</td>';				
    				echo '<td>'.$intake['Profession']['name'].'</td>';
    				echo '<td>'.$intake['Learningform']['name'].'</td>';	
    				echo '<td>'.$intake['Learningtype']['name'].'</td>';
    				echo '<td>'; 
    				echo $html->link(__('Удалить', true), array('controller' => 'targetingintakes', 'action' => 'delete', 'id' => $intake['Targetingintake']['id']), array('target' => '_blank'));
    				echo '</td>';
    				echo '</tr>';
    			}
    			echo '</table>';
    		}
  		?>
  	</td>
  	<td>
  		<?php 
  			echo $html->link(__('Добавить целевой набор', true), array('controller' => 'targetingintakes', 'action' => 'add', 'abiturient' => $this->data['Abiturient']['id']), array('target' => '_blank'));
  		?>
  	</td>
  </tr>  
  <tr>
  	<td colspan="4"><hr /></td>
  </tr>          
   <tr>
    <td colspan="4"><strong>Дополнительная информация</strong></td>
  </tr>     
   <tr>
    <td width="25%">ИНН</td>
    <td width="25%"><?php echo $form->input('inn', array('label' => '', 'size' =>30)); ?></td>
    <td width="25%" align="right">Страховое св-во</td>
    <td width="50%"><?php echo $form->input('insurance', array('label' => '', 'size' =>30)); ?></td>
  </tr> 
   <tr>
    <td width="25%">Пенсионное св-во</td>
    <td colspan="3"><?php echo $form->input('pension_certificate', array('label' => '', 'size' =>30)); ?></td>
  </tr> 
   <tr>
    <td width="25%">Прививки</td>
    <td colspan="3"><?php echo $form->input('inoculations', array('label' => '', 'size' =>30)); ?></td>
  </tr>  
  <tr>
  	<td colspan="4"><hr /></td>
  </tr>
   <tr>
    <td colspan="4"><strong>Дополнительная информация</strong></td>
  </tr>  
    <tr>
    <td width="25%"></td>
    <td colspan="3"><?php echo $form->input('moreinfo', array('label' => '')); ?></td>
  </tr>  
  <tr>
  	<td colspan="4"><hr /></td>
  </tr>     
   <tr>
    <td width="25%">&nbsp;</td>
    <td width="25%">&nbsp;</td>
    <td width="25%" align="right"><b>Оформить</b></td>
    <td width="50%"><?php echo $form->input('prepared', array('label' => '')); ?></td>
  </tr>
  <!-- 
   <tr>
    <td width="25%">&nbsp;</td>
    <td width="25%">&nbsp;</td>
    <td width="25%" align="right"><b>Учесть для рейтинга</b></td>
    <td width="25%"><?php echo $form->input('approved', array('label' => '')); ?></td>
  </tr>
    <tr>
    <td width="25%">&nbsp;</td>
    <td width="25%">&nbsp;</td>
    <td width="25%" align="right"><b>Зачислить</b></td>
    <td width="25%"><?php echo $form->input('enrolled', array('label' => '')); ?></td>
  </tr>         
   -->      		
 </table>		
 	</fieldset>
	<br />
	<?php echo $form->end('Сохранить');?>
</div>
<?php 
//debug ($selectedprofessions);
?>